<?php
//*********************************** 
//Universal Media Publishing Platform
//Functions
//*********************************** 
function TitleToURL($str){
	$replace[0]["in"]="а";
	$replace[0]["out"]="a";

	$replace[1]["in"]="б";
	$replace[1]["out"]="b";   

	$replace[2]["in"]="в";
	$replace[2]["out"]="v";   

	$replace[3]["in"]="г";
	$replace[3]["out"]="g";

	$replace[4]["in"]="д";
	$replace[4]["out"]="d";  

	$replace[5]["in"]="е";
	$replace[5]["out"]="e";  

	$replace[6]["in"]="ё";
	$replace[6]["out"]="jo";  

	$replace[7]["in"]="ж";
	$replace[7]["out"]="zh";  

	$replace[8]["in"]="з";
	$replace[8]["out"]="z"; 

	$replace[9]["in"]="и";
	$replace[9]["out"]="i"; 

	$replace[10]["in"]="й";
	$replace[10]["out"]="j";  

	$replace[11]["in"]="к";
	$replace[11]["out"]="k";  

	$replace[12]["in"]="л";
	$replace[12]["out"]="l";  

	$replace[13]["in"]="м";
	$replace[13]["out"]="m";  

	$replace[14]["in"]="н";
	$replace[14]["out"]="n";  

	$replace[15]["in"]="о";
	$replace[15]["out"]="o";  

	$replace[16]["in"]="п";
	$replace[16]["out"]="p";  

	$replace[17]["in"]="р";
	$replace[17]["out"]="r";  

	$replace[18]["in"]="с";
	$replace[18]["out"]="s";  

	$replace[19]["in"]="т";
	$replace[19]["out"]="t";  

	$replace[20]["in"]="у";
	$replace[20]["out"]="u";  

	$replace[21]["in"]="ф";
	$replace[21]["out"]="f";  

	$replace[22]["in"]="х";
	$replace[22]["out"]="h";  

	$replace[23]["in"]="ц";
	$replace[23]["out"]="c";  

	$replace[24]["in"]="ч";
	$replace[24]["out"]="ch";  

	$replace[25]["in"]="ш";
	$replace[25]["out"]="sh";  

	$replace[26]["in"]="щ";
	$replace[26]["out"]="w";  

	$replace[27]["in"]="ъ";
	$replace[27]["out"]="";

	$replace[28]["in"]="ы";
	$replace[28]["out"]="y";  

	$replace[29]["in"]="ь";
	$replace[29]["out"]=""; 

	$replace[30]["in"]="э";
	$replace[30]["out"]="je"; 

	$replace[31]["in"]="ю";
	$replace[31]["out"]="ju";  

	$replace[32]["in"]="я";
	$replace[32]["out"]="ja";     

		$replace[33]["in"]="А";
	$replace[33]["out"]="A";

	$replace[34]["in"]="Б";
	$replace[34]["out"]="B";   

	$replace[35]["in"]="В";
	$replace[35]["out"]="V";   

	$replace[36]["in"]="Г";
	$replace[36]["out"]="G";

	$replace[37]["in"]="Д";
	$replace[37]["out"]="D";  

	$replace[38]["in"]="Е";
	$replace[38]["out"]="E";  

	$replace[39]["in"]="Ё";
	$replace[39]["out"]="Jo";  

	$replace[40]["in"]="Ж";
	$replace[40]["out"]="Zh";  

	$replace[41]["in"]="З";
	$replace[41]["out"]="Z"; 

	$replace[42]["in"]="И";
	$replace[42]["out"]="I"; 

	$replace[43]["in"]="Й";
	$replace[43]["out"]="J";  

	$replace[44]["in"]="К";
	$replace[44]["out"]="K";  

	$replace[45]["in"]="Л";
	$replace[45]["out"]="L";  

	$replace[46]["in"]="М";
	$replace[46]["out"]="M";  

	$replace[47]["in"]="Н";
	$replace[47]["out"]="N";  

	$replace[48]["in"]="О";
	$replace[48]["out"]="O";  

	$replace[49]["in"]="П";
	$replace[49]["out"]="P";  

	$replace[50]["in"]="Р";
	$replace[50]["out"]="R";  

	$replace[51]["in"]="С";
	$replace[51]["out"]="S";  

	$replace[52]["in"]="Т";
	$replace[52]["out"]="T";  

	$replace[53]["in"]="У";
	$replace[53]["out"]="U";  

	$replace[54]["in"]="Ф";
	$replace[54]["out"]="F";  

	$replace[55]["in"]="Х";
	$replace[55]["out"]="H";  

	$replace[56]["in"]="Ц";
	$replace[56]["out"]="C";  

	$replace[57]["in"]="Ч";
	$replace[57]["out"]="Ch";  

	$replace[58]["in"]="Ш";
	$replace[58]["out"]="Sh";  

	$replace[59]["in"]="Щ";
	$replace[59]["out"]="W";  

	$replace[60]["in"]="Ъ";
	$replace[60]["out"]="";

	$replace[61]["in"]="Ы";
	$replace[61]["out"]="Y";  

	$replace[62]["in"]="Ь";
	$replace[62]["out"]=""; 

	$replace[63]["in"]="Э";
	$replace[63]["out"]="Je"; 

	$replace[64]["in"]="Ю";
	$replace[64]["out"]="Ju";  

	$replace[65]["in"]="Я";
	$replace[65]["out"]="Ja"; 
	
	$replace[66]["in"]=" ";
	$replace[66]["out"]="-";    

	$replace[67]["in"]="&#039;";
	$replace[67]["out"]=""; 

	$replace[68]["in"]="'";
	$replace[68]["out"]=""; 

	for ($i = 0; $i < count($replace); $i++) {
	$str =str_replace($replace[$i]["in"], $replace[$i]["out"], $str);
	}
	return $str;
}

function endKey($array){
    end($array);
    return key($array);
} 

function showalbumlist(){
	global $albums;
	for ($s = 0; $s < count($albums); $s++) {
		echo '<a href="album.php?id='.$albums[$s]["alid"]. '">'.$albums[$s]["title"].'</a>';
	} 
}

function pagenfo($pager){
	global $posts, $total, $page, $start, $num;
	$posts = mysql_result($pager, 0); 
	$total = intval(($posts - 1) / $num) + 1; 
	$page = intval($page); 
	if(empty($page) or $page < 0) $page = 1; 
	if($page > $total) $page = $total; 
	$start = $page * $num - $num; 
} 

function sortby($sorttype,$sortname,$url){
	global $sorting, $st;
	if (($sorting == $sorttype)&&($st == "ASC")) $s = "down"; 
	else $s = "up" ;
	echo '<a href="'.$url.'/by-'.$sorttype.'-'.$s.'">';
	if ($sorting == $sorttype){
		echo '[';
		if ($s == "up") echo '<'; 
		else echo '>';
	}
	echo $sortname;
	if ($sorting == $sorttype) echo ']';
	echo '</a>';
}
?>